<template>
  <div class="knowledge-list">
    <el-table 
      :data="knowledgeList" 
      style="width: 100%"
      @row-click="handleRowClick"
    >
      <el-table-column prop="name" label="知识库名称" />
      <el-table-column prop="description" label="描述" />
      <el-table-column prop="documentCount" label="文档数量" width="100" />
      <el-table-column prop="createTime" label="创建时间" width="180" />
      <el-table-column label="操作" width="120" fixed="right">
        <template #default="{ row }">
          <el-button-group>
            <el-button type="primary" link @click.stop="$emit('edit', row)">
              <el-icon><Edit /></el-icon>
            </el-button>
            <el-button type="danger" link @click.stop="handleDelete(row)">
              <el-icon><Delete /></el-icon>
            </el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { Edit, Delete } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'

const props = defineProps({
  knowledgeList: {
    type: Array,
    default: () => []
  }
})

const emit = defineEmits(['edit', 'delete', 'select'])

const handleRowClick = (row) => {
  emit('select', row)
}

const handleDelete = (row) => {
  ElMessageBox.confirm(
    '确定要删除该知识库吗？删除后无法恢复。',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }
  ).then(() => {
    emit('delete', row)
  })
}
</script>

<style scoped>
.knowledge-list {
  margin-top: 20px;
}

:deep(.el-table__row) {
  cursor: pointer;
}
</style>
